//职位模块
import React, { Component } from 'react'
import {
    View,
    Text,
    ImageBackground
} from 'react-native';
let Dimensions = require('Dimensions');
let width = Dimensions.get('window').width;

// 新加的顶部轮播
import New_postop from './postionComponent/new_postop'
import New_postop2 from './postionComponent/new_postop2'
import Loading from '../../util/loading/loading'
//职位组件
import Content from './postionComponent/Content'
import { fetchRequest } from "../../util/fetch";

export default class Postion extends Component {
    constructor(props) {
        super(props);
        this.state = {
            postop_List: [],
            postop2_List: [],
        }
    }

    //加载后渲染页面
    componentDidMount() {
        fetchRequest('Postion/selPostion.go', 'POST', { page: 1 }).then(ret => {
            if (ret.postionList.length > 0 && ret.postionList.length < 4) {
                let list = [];
                for (var i = 0; i < ret.postionList.length; i++) {
                    list.push(ret.postionList[i]);
                }
                this.setState({ postop_List: list });
            } else if (ret.postionList.length > 0 && ret.postionList.length < 7) {
                let list = [];
                let list1 = [];
                for (var i = 0; i < 3; i++) {
                    list.push(ret.postionList[i]);
                }
                for (var i = 3; i < ret.postionList.length; i++) {
                    list1.push(ret.postionList[i]);
                }
                this.setState({ postop_List: list, postop2_List: list1 });
            }

        })
    }

    render() {
        if (!this.state.postop_List.length > 0) {
            return (
                // <View style={{
                //     marginVertical: 10, height: 100, alignItems: 'center', justifyContent: 'flex-end'
                // }}>
                //     <Text>玩命加载ing</Text>
                // </View>
                <Loading/>
                );
        } else {
            return (
                <View style={{ flex: 1, backgroundColor: '#f6f6f6' }}>
                    {/* <Nav navigation={this.props.navigation} /> */}
                    {/* <Type navigation={this.props.navigation} /> */}
                    <ImageBackground style={{ width: width * 1,height:90 }} source={require('../../img/app/zi.jpg')} resizeMode='cover'>
                        <New_postop postop_List={this.state.postop_List} navigation={this.props.navigation} />
                        <New_postop2 postop2_List={this.state.postop2_List} navigation={this.props.navigation} />
                    </ImageBackground>

                    <Content navigation={this.props.navigation} />
                </View>
            )
        }
    }

}